package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.dao.DoingDao;
import cn.sumpu.app.guoguojie.domain.Comment;
import cn.sumpu.app.guoguojie.domain.Doing;
import cn.sumpu.app.guoguojie.domain.DoingAudit;
import cn.sumpu.app.guoguojie.domain.DoingPicture;
import cn.sumpu.app.guoguojie.domain.DoingProduct;
import cn.sumpu.app.guoguojie.domain.DoingProductAudit;
import cn.sumpu.app.guoguojie.domain.DoingProductTime;
import cn.sumpu.app.guoguojie.domain.DoingStat;
import cn.sumpu.app.guoguojie.domain.DoingSync;
import cn.sumpu.app.guoguojie.domain.DoingTopic;
import cn.sumpu.app.guoguojie.domain.DoingTopicRelation;
import cn.sumpu.app.guoguojie.domain.Ext.DoingExt;
import cn.sumpu.app.guoguojie.domain.Ext.FollowFans;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class DoingDaoImpl extends SqlSessionDaoSupport implements DoingDao {

    private final static Logger logger = LoggerFactory.getLogger(DoingDaoImpl.class);

    public void insert(Doing doing) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insert", doing);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Write database failure.", e);
            }
            throw new AppBusinessException("Write database failure.", e);
        }
    }

    public void update(Doing doing) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.DoingMapper.update", doing);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("update database failure.", e);
            }
            throw new AppBusinessException("update database failure.", e);
        }

    }

    public Doing getDoingById(String id) throws AppBusinessException {
        try {
            return (Doing) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public Doing getRootDoingById(String id) throws AppBusinessException {
        try {
            return (Doing) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getRootDoingById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    public Doing getDoingByFamily(String family) throws AppBusinessException {
        try {
            return (Doing) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingByFamily", family);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    public Doing getDoingByMember(String member) throws AppBusinessException {
        try {
            return (Doing) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingByMember", member);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    public List<Doing> getDoingList(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public int getDoingListCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingListCount", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    public void deleteDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.delete", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }

    }

    //更新微博的量值(+1)
    @Override
    public void updateDoingAdd(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.updateDoingAdd", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("update database failure.", e);
            }
            throw new AppBusinessException("update database failure.", e);
        }

    }

    @Override
    public void insertTopic(DoingTopic doingTopic) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertTopic", doingTopic);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Write database failure.", e);
            }
            throw new AppBusinessException("Write database failure.", e);
        }

    }

    @Override
    public void insertTopicRelation(DoingTopicRelation topicRelation) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertTopicRelation", topicRelation);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Write database failure.", e);
            }
            throw new AppBusinessException("Write database failure.", e);
        }

    }

    @SuppressWarnings("unchecked")
    public List<DoingExt> getDoingByTopic(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingByTopic", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public int getDoingCountByTopic(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingCountByTopic", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public int countDoingByKeywords(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.countDoingByKeywords", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Count doing by keywords failure.", e);
            }
            throw new AppBusinessException("Count doing by keywords failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingByKeywords(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingByKeywords", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Get doing by keywords failure.", e);
            }
            throw new AppBusinessException("Get doing by keywords failure.", e);
        }
    }

    /**
     * author Bruce Zhang
     * @return 取得20个家庭最新的的一条微博
     * @throws AppBusinessException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingNewest() throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingNewest");
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingNewest failure.", e);
            }
            throw new AppBusinessException("getDoingNewest failure.", e);
        }
    }

    /**
     * author Bruce Zhang
     * @param map	参数集合（1.doorplate:门牌号 2.title:图片标题 3.startTime:开始时间 4.endTime:结束时间）
     * @return	根据条件查询微博列表
     * @throws AppBusinessException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingByCondition(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingByCondition", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingByCondition database failure.", e);
            }
            throw new AppBusinessException("getDoingByCondition database failure.", e);
        }
    }

    //根据条件查询微博列表的长度
    @Override
    public int getDoingCountByCondition(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingCountByCondition", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingCountByCondition database failure.", e);
            }
            throw new AppBusinessException("getDoingCountByCondition database failure.", e);
        }
    }

    //根据DoingId集合批量屏蔽微博
    @Override
    public void updateByDoingIdList(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.DoingMapper.updateByDoingIdList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateByDoingIdList database failure.", e);
            }
            throw new AppBusinessException("updateByDoingIdList database failure.", e);
        }
    }

    //根据DoingId集合批量删除微博
    @Override
    public void deleteByDoingIdList(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.DoingMapper.deleteByDoingIdList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteByDoingIdList database failure.", e);
            }
            throw new AppBusinessException("deleteByDoingIdList database failure.", e);
        }
    }

    //根据微博的标签查询微博
    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingListByTag(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingListByTag", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingListByTag database failure.", e);
            }
            throw new AppBusinessException("getDoingListByTag database failure.", e);
        }
    }

    //根据微博的标签查询微博总条数
    @Override
    public Integer getDoingCountByTag(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingCountByTag", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingCountByTag database failure.", e);
            }
            throw new AppBusinessException("getDoingCountByTag database failure.", e);
        }
    }

    //根据微博的ID取得两条该微博的评论
    @SuppressWarnings("unchecked")
    @Override
    public List<Comment> getCommentListByDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Comment>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getCommentListByDoing", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getCommentListByDoing database failure.", e);
            }
            throw new AppBusinessException("getCommentListByDoing database failure.", e);
        }
    }

    @Override
    public void deleteDoingProduct(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.deleteDoingProduct", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteDoingProduct database failure.", e);
            }
            throw new AppBusinessException("deleteDoingProduct database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingProduct> getDoingProductList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingProduct>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingProductList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingProductList database failure.", e);
            }
            throw new AppBusinessException("getDoingProductList database failure.", e);
        }
    }

    public int getDoingProductListCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingProductListCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingProductList database failure.", e);
            }
            throw new AppBusinessException("getDoingProductList database failure.", e);
        }
    }

    @Override
    public void insertDoingProduct(DoingProduct doingProduct) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertDoingProduct", doingProduct);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("insertDoingProduct database failure.", e);
            }
            throw new AppBusinessException("insertDoingProduct database failure.", e);
        }
    }

    @Override
    public void deleteDoingPicture(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.deleteDoingPicture", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteDoingPicture database failure.", e);
            }
            throw new AppBusinessException("deleteDoingPicture database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingPicture> getDoingPictureList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingPicture>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingPictureList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingPictureList database failure.", e);
            }
            throw new AppBusinessException("getDoingPictureList database failure.", e);
        }
    }

    @Override
    public void insertDoingPicture(DoingPicture doingPicture) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertDoingPicture", doingPicture);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("insertDoingPicture database failure.", e);
            }
            throw new AppBusinessException("insertDoingPicture database failure.", e);
        }

    }

    //根据频道查询商品列表
    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingListByChannel(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingListByChannel", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingListByChannel database failure.", e);
            }
            throw new AppBusinessException("getDoingListByChannel database failure.", e);
        }
    }

    //根据频道查询商品列表长度
    @Override
    public Integer getDoingCountByChannel(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingCountByChannel", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingCountByChannel database failure.", e);
            }
            throw new AppBusinessException("getDoingCountByChannel database failure.", e);
        }
    }

    //童鞋配饰的格子
    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingGrid(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingGrid", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingGrid database failure.", e);
            }
            throw new AppBusinessException("getDoingGrid database failure.", e);
        }
    }

    //根据频道查询帖子
    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getPostsListByChannel(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getPostsListByChannel", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPostsListByChannel database failure.", e);
            }
            throw new AppBusinessException("getPostsListByChannel database failure.", e);
        }
    }

    @Override
    public void deleteFollow(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.deleteFollow", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("insertDoingPicture database failure.", e);
            }
            throw new AppBusinessException("insertDoingPicture database failure.", e);
        }
    }

    @Override
    public int getFollowCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getFollowCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getFollowCount database failure.", e);
            }
            throw new AppBusinessException("getFollowCount database failure.", e);
        }
    }

    @Override
    public void insertFollow(Map<String, Object> map) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertFollow", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("insertFollow database failure.", e);
            }
            throw new AppBusinessException("insertFollow database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<FollowFans> getFansList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<FollowFans>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getFansList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getFansList database failure.", e);
            }
            throw new AppBusinessException("getFansList database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<FollowFans> getFollowList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<FollowFans>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getFollowList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getFollowList database failure.", e);
            }
            throw new AppBusinessException("getFollowList database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getFollowDoingList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getFollowDoingList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getFollowList database failure.", e);
            }
            throw new AppBusinessException("getFollowList database failure.", e);
        }
    }

    @Override
    public int getFollowDoingListCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getFollowDoingListCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getFollowDoingListCount database failure.", e);
            }
            throw new AppBusinessException("getFollowDoingListCount database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingListByIds(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingListByIds", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingListByIds database failure.", e);
            }
            throw new AppBusinessException("getDoingListByIds database failure.", e);
        }
    }

    @Override
    public int getDoingListByIdsCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingListByIdsCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingListByIdsCount database failure.", e);
            }
            throw new AppBusinessException("getDoingListByIdsCount database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingAll() throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingAll");
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingAll database failure.", e);
            }
            throw new AppBusinessException("getDoingAll database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingListByDoingIds(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingListByDoingIds", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingListByDoingIds database failure.", e);
            }
            throw new AppBusinessException("getDoingListByDoingIds database failure.", e);
        }
    }

    @Override
    public int getDoingListByDoingIdsCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingListByDoingIdsCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingListByDoingIdsCount database failure.", e);
            }
            throw new AppBusinessException("getDoingListByDoingIdsCount database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    public List<DoingProductAudit> getDoingProductAuditList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingProductAudit>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingProductAuditList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingProductAuditList failure.", e);
            }
            throw new AppBusinessException("getDoingProductAuditList failure.", e);
        }

    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingAudit> getDoingAuditList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingAudit>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingAuditList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingAuditList failure.", e);
            }
            throw new AppBusinessException("getDoingAuditList failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    public List<DoingProduct> getProductListByProductIds(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingProduct>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getProductListByProductIds", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getProductListByProductIds database failure.", e);
            }
            throw new AppBusinessException("getProductListByProductIds database failure.", e);
        }
    }

    @Override
    public int getProductListByProductIdsCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getProductListByProductIdsCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getProductListByProductIdsCount database failure.", e);
            }
            throw new AppBusinessException("getProductListByProductIdsCount database failure.", e);
        }
    }

    @Override
    public int deleteDoingAuditByIds(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.deleteDoingAuditByIds", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteDoingAuditByIds failure.", e);
            }
            throw new AppBusinessException("deleteDoingAuditByIds failure.", e);
        }
    }

    @Override
    public int deleteDoingProductAudit(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.deleteDoingProductAudit", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteDoingProductAudit failure.", e);
            }
            throw new AppBusinessException("deleteDoingProductAudit failure.", e);
        }
    }

    @Override
    public int deleteDoingProductAuditByIds(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.deleteDoingProductAuditByIds", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deleteDoingProductAuditByIds failure.", e);
            }
            throw new AppBusinessException("deleteDoingProductAuditByIds failure.", e);
        }
    }

    @Override
    public int isFollowMe(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.isFollowMe", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingByMyFamily(Map<String, Object> map) throws AppBusinessException {
        try {

            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingByMyFamily", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingByMyFamily database failure.", e);
            }
            throw new AppBusinessException("getDoingByMyFamily database failure.", e);
        }
    }

    @Override
    public int getDoingByMyFamilyCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingByMyFamilyCount", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getMentionByMyFamily(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getMentionByMyFamily", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getMentionByMyFamily database failure.", e);
            }
            throw new AppBusinessException("getMentionByMyFamily database failure.", e);
        }
    }

    @Override
    public int getMentionByMyFamilyCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getMentionByMyFamilyCount", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingProduct> getOtherLoveDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingProduct>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.otherLoveDoing", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("loveThisLoveThatList database failure.", e);
            }
            throw new AppBusinessException("loveThisLoveThatList database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getForwardDoingList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getForwardDoingList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getForwardDoingList database failure.", e);
            }
            throw new AppBusinessException("getForwardDoingList database failure.", e);
        }
    }

    @Override
    public int getForwardDoingListCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getForwardDoingListCount", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public void updateDoingPicture(DoingPicture doingPicture) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.DoingMapper.updateDoingPicture", doingPicture);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateDoingPicture failure.", e);
            }
            throw new AppBusinessException("updateDoingPicture failure.", e);
        }
    }

    @Override
    public void updateDoingProduct(DoingProduct doingProdct) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.DoingMapper.updateDoingProduct", doingProdct);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateDoingProduct failure.", e);
            }
            throw new AppBusinessException("updateDoingProduct failure.", e);
        }
    }

    @Override
    public void insertDoingStat(DoingStat doingStat) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertDoingStat", doingStat);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Write database failure.", e);
            }
            throw new AppBusinessException("Write database failure.", e);
        }
    }

    @Override
    public void updateViewDoingIP(DoingStat doingStat) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.DoingMapper.updateViewDoingIP", doingStat);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateViewDoingIP failure.", e);
            }
            throw new AppBusinessException("updateViewDoingIP failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingStatList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<Doing>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingStatList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingStatList database failure.", e);
            }
            throw new AppBusinessException("getDoingStatList database failure.", e);
        }
    }

    @Override
    public int getDoingStatListCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingStatListCount", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public DoingStat getDoingStatByIp(Map<String, Object> map) throws AppBusinessException {
        try {
            return (DoingStat) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingStatByIp", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    //查询这条微博有几个图片
    @Override
    public int getPicCountByDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getPicCountByDoing", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPicCountByDoing query database failure.", e);
            }
            throw new AppBusinessException("getPicCountByDoing query database failure.", e);
        }
    }

    //查询这条微博有几个商品
    @Override
    public int getProCountByDoing(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getProCountByDoing", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getProCountByDoing query database failure.", e);
            }
            throw new AppBusinessException("getProCountByDoing query database failure.", e);
        }
    }

    //查询这条微博画报号
    @Override
    public String getPictorialByDoing(String doingId) throws AppBusinessException {
        try {
            return (String) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getPictorialByDoing", doingId);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getPictorialByDoing query database failure.", e);
            }
            throw new AppBusinessException("getPictorialByDoing query database failure.", e);
        }
    }

    @Override
    public void insert(DoingSync doingSync) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertDoingSync", doingSync);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Write database failure.", e);
            }
            throw new AppBusinessException("Write database failure.", e);
        }

    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingSync> getDoingSync(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingSync", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public void deletePostSyncById(String id) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.DoingMapper.deletePostSyncById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("deletePostSync database failure.", e);
            }
            throw new AppBusinessException("deletePostSync database failure.", e);
        }

    }

    @Override
    public void updateDoingSync(DoingSync doingSync) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.DoingMapper.updateDoingSync", doingSync);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("update database failure.", e);
            }
            throw new AppBusinessException("update database failure.", e);
        }

    }

    @Override
    public int getDoingProCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingProCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingProCount query database failure.", e);
            }
            throw new AppBusinessException("getDoingProCount query database failure.", e);
        }
    }

    @Override
    public int getDoingPicCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingPicCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingPicCount query database failure.", e);
            }
            throw new AppBusinessException("getDoingPicCount query database failure.", e);
        }
    }

    @Override
    public int getMyRelpycCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getMyRelpycCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getMyRelpycCount query database failure.", e);
            }
            throw new AppBusinessException("getMyRelpycCount query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getMyRelpy(String family) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getMyRelpy", family);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public int getMyPictorialBadge(String family) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingPictorialMapper.getMyPictorialBadge", family);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getMyPictorialBadge query database failure.", e);
            }
            throw new AppBusinessException("getMyPictorialBadge query database failure.", e);
        }
    }

    @Override
    public DoingProduct getDoingProductById(String id) throws AppBusinessException {
        try {
            return (DoingProduct) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingProductById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    @Override
    public DoingPicture getDoingPictureById(String id) throws AppBusinessException {
        try {
            return (DoingPicture) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingPictureById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query database failure.", e);
            }
            throw new AppBusinessException("query database failure.", e);
        }
    }

    //根据商品Id查询产品的所有属性
    @Override
    public DoingProduct getDpById(String id) throws AppBusinessException {
        try {
            return (DoingProduct) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDpById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDpById database failure.", e);
            }
            throw new AppBusinessException("getDpById database failure.", e);
        }
    }

    //查询画报的商品(后台ETAO)
    @SuppressWarnings("unchecked")
    @Override
    public List<DoingProduct> getProductByPictorial(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingProduct>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getProductByPictorial", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getProductByPictorial database failure.", e);
            }
            throw new AppBusinessException("getProductByPictorial database failure.", e);
        }
    }

    //查询这个商品是否被分享过
    @Override
    public DoingProduct getProductContain(Map<String, Object> map) throws AppBusinessException {
        try {
            return (DoingProduct) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getProductContain", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getProductContain database failure.", e);
            }
            throw new AppBusinessException("getProductContain database failure.", e);
        }
    }

    //查询这些商品是否被分享过
    @SuppressWarnings("unchecked")
    @Override
    public List<DoingProduct> getProductsContain(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<DoingProduct>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getProductsContain", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getProductsContain database failure.", e);
            }
            throw new AppBusinessException("getProductsContain database failure.", e);
        }
    }

    @Override
    public void insertDoingProductTime(DoingProductTime doingProductTime) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.DoingMapper.insertDoingProductTime", doingProductTime);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Write database failure.", e);
            }
            throw new AppBusinessException("Write database failure.", e);
        }
    }

    /**
     * @param map
     * @return
     * @throws AppBusinessException
     * @see cn.sumpu.app.guoguojie.dao.DoingDao#getDoingProductTime(java.util.Map)
     */
    @Override
    public DoingProductTime getDoingProductTime(Map<String, Object> map) throws AppBusinessException {
        try {
            return (DoingProductTime) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingProductTime", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Query database failure.", e);
            }
            throw new AppBusinessException("Query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<DoingProductTime> getFanliProduct(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getFanliProduct", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Query database failure.", e);
            }
            throw new AppBusinessException("Query database failure.", e);
        }
    }

    @Override
    public int getFanliProductCount(Map<String, Object> map) throws AppBusinessException {
        return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getFanliProductCount", map);
    }

    /**
     * @param productId
     * @return
     * @throws AppBusinessException
     * @see cn.sumpu.app.guoguojie.dao.DoingDao#getHasProductTime(java.lang.String)
     */
    @Override
    public DoingProductTime getHasProductTime(String productId) throws AppBusinessException {
        try {
            return (DoingProductTime) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getHasProductTime", productId);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Query database failure.", e);
            }
            throw new AppBusinessException("Query database failure.", e);
        }
    }

    //查询微博
    @SuppressWarnings("unchecked")
    @Override
    public List<Doing> getDoingBruce(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingBruce", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingBruce database failure.", e);
            }
            throw new AppBusinessException("getDoingBruce database failure.", e);
        }
    }

    //查询商品
    @SuppressWarnings("unchecked")
    @Override
    public List<DoingProduct> getProductBruce(Map<String, Object> map) throws AppBusinessException {
        try {
            return getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.DoingMapper.getProductBruce", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getProductBruce database failure.", e);
            }
            throw new AppBusinessException("getProductBruce database failure.", e);
        }
    }

    @Override
    public int getDoingSyncCount(Map<String, Object> map) throws AppBusinessException {
        try {
            Object obj = getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.DoingMapper.getDoingSyncCount", map);
            return (Integer) (obj == null ? 0 : obj);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("getDoingSyncCount failure.", e);
            }
            throw new AppBusinessException("getDoingSyncCount failure.", e);
        }
    }

}
